/*
 * Gui.h
 *
 *  Created on: 03.06.2011
 *      Author: ansuz
 */

#ifndef GUI_H_
#define GUI_H_

#include <vector>
#include <utility>
#include <string>
#include <rodos.h>
#include "worker-monitor-topics.h"
#include "SatelliteInterface.h"

using namespace std;


class Gui : public Thread {
private:
	static const int maxNumDataRecords;
	static const int lineBeginningOfData;
	static const int infoLine;
	static const int nodeLine;
	static const int lineReply;
	static const int lineLegend;
	static const int lineInput;
	static const int refreshPeriod; //ms
	static int numFields;
	//Singleton pointer
	static Gui *singleton;

	//Describes what data is transmitted and how the data fields are called
	DataDescription description;

	//Last input
	pair<unsigned int, void*> lastDataInput;
	string statusMessage;
	vector<int> nodeList;
	int workerID;
	string consoleInput;
	string reply;
	bool toggleInfo;


	//Parses and displays the input data using the format description above
	//Not in putGeneric() to reduce unneeded calls resulting from the singleton concept
	void display(const unsigned int len, const void* msg);

	//Moves the Pointer to the needed position for displaying a specific data field
	//index tells the index of the dataField-array that describes the data field
	void movePointer(int index);
	
	//void getStatusData();
	StatusData statusData;
	CommBuffer<StatusData> wStatusBuffer;
	Subscriber wStatusSubscriber;
	
	SatelliteInterface *satelliteInterface;
	int numNodes;
	int numDisabledNodes;
	int numResponsiveNodes;
	int* nodeIDList;

public:
	Gui(DataDescription dd);


	//Inherited from Initiator
	virtual void init(void);

	virtual void run(void);

	//Inherited from Putter, needs pointer to data struct
	virtual void setStatus(const unsigned int len, const void* msg);

	//Sets the information to display
	void setInfoMessage(const char* msg);
	void setNodeList(int len, int* IDs);
	void setWorker(int ID);
	void setConsoleInput(const char* msg);
	void setReply(const char* msg);
	void setToggleInfo();

	//Refreshes the interface
	void refresh();

	void parseDataDescription(DataDescription dd);

	Gui* getSingletonPtr();
};

Gui mainGui(housekeepingData);

#endif /* GUI_H_ */
